home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_bas / mquery.zip / MDYNAST.FRM < prev    next >
Text File  |  1994-05-24  |  26KB  |  1,037 lines

  1. VERSION 2.00
  2. Begin Form fDynaset 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    ClientHeight    =   3750
  6.    ClientLeft      =   1410
  7.    ClientTop       =   2415
  8.    ClientWidth     =   5655
  9.    ClipControls    =   0   'False
  10.    Height          =   4155
  11.    Icon            =   MDYNAST.FRX:0000
  12.    KeyPreview      =   -1  'True
  13.    Left            =   1350
  14.    LinkTopic       =   "Form1"
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   3733.906
  17.    ScaleMode       =   0  'User
  18.    ScaleWidth      =   5675.317
  19.    Tag             =   "Dynaset"
  20.    Top             =   2070
  21.    Width           =   5775
  22.    Begin PictureBox FieldHeader 
  23.       BackColor       =   &H00C0C0C0&
  24.       BorderStyle     =   0  'None
  25.       Height          =   240
  26.       Left            =   0
  27.       ScaleHeight     =   240
  28.       ScaleMode       =   0  'User
  29.       ScaleWidth      =   5028
  30.       TabIndex        =   15
  31.       Top             =   480
  32.       Width           =   5025
  33.       Begin Label FieldHdrLabel 
  34.          BackColor       =   &H00C0C0C0&
  35.          Caption         =   "Field Name:"
  36.          Height          =   252
  37.          Left            =   120
  38.          TabIndex        =   16
  39.          Top             =   0
  40.          Width           =   1212
  41.       End
  42.    End
  43.    Begin PictureBox ViewButtons 
  44.       Align           =   1  'Align Top
  45.       BackColor       =   &H00C0C0C0&
  46.       BorderStyle     =   0  'None
  47.       Height          =   495
  48.       Left            =   0
  49.       ScaleHeight     =   495
  50.       ScaleMode       =   0  'User
  51.       ScaleWidth      =   5658.376
  52.       TabIndex        =   0
  53.       Top             =   0
  54.       Width           =   5655
  55.       Begin CommandButton SortButton 
  56.          Caption         =   "&Sort"
  57.          Height          =   330
  58.          Left            =   3128
  59.          TabIndex        =   17
  60.          Top             =   0
  61.          Width           =   650
  62.       End
  63.       Begin CommandButton FilterButton 
  64.          Caption         =   "F&ilter"
  65.          Height          =   330
  66.          Left            =   2520
  67.          TabIndex        =   22
  68.          Top             =   0
  69.          Width           =   650
  70.       End
  71.       Begin CommandButton CloseButton 
  72.          Cancel          =   -1  'True
  73.          Caption         =   "&Close"
  74.          Height          =   330
  75.          Left            =   3780
  76.          TabIndex        =   8
  77.          TabStop         =   0   'False
  78.          Top             =   0
  79.          Width           =   650
  80.       End
  81.       Begin CommandButton DelButton 
  82.          Caption         =   "&Del"
  83.          Height          =   330
  84.          Left            =   1260
  85.          TabIndex        =   4
  86.          Top             =   0
  87.          Width           =   650
  88.       End
  89.       Begin CommandButton EditButton 
  90.          Caption         =   "&Edit"
  91.          Height          =   330
  92.          Left            =   630
  93.          TabIndex        =   3
  94.          Top             =   0
  95.          Width           =   650
  96.       End
  97.       Begin CommandButton AddButton 
  98.          Caption         =   "&Add"
  99.          Height          =   330
  100.          Left            =   0
  101.          TabIndex        =   2
  102.          Top             =   0
  103.          Width           =   650
  104.       End
  105.       Begin CommandButton FindButton 
  106.          Caption         =   "&Find"
  107.          Height          =   330
  108.          Left            =   1890
  109.          TabIndex        =   1
  110.          Top             =   0
  111.          Width           =   650
  112.       End
  113.    End
  114.    Begin PictureBox ChangeButtons 
  115.       BackColor       =   &H00C0C0C0&
  116.       BorderStyle     =   0  'None
  117.       Height          =   480
  118.       Left            =   0
  119.       ScaleHeight     =   480
  120.       ScaleMode       =   0  'User
  121.       ScaleWidth      =   5028
  122.       TabIndex        =   5
  123.       Top             =   0
  124.       Visible         =   0   'False
  125.       Width           =   5028
  126.       Begin CommandButton UpdateButton 
  127.          Caption         =   "&Update"
  128.          Height          =   372
  129.          Left            =   960
  130.          TabIndex        =   7
  131.          Top             =   48
  132.          Width           =   1212
  133.       End
  134.       Begin CommandButton CancelButton 
  135.          Caption         =   "&Cancel"
  136.          Height          =   372
  137.          Left            =   2640
  138.          TabIndex        =   6
  139.          Top             =   48
  140.          Width           =   1212
  141.       End
  142.    End
  143.    Begin PictureBox StatBox 
  144.       Align           =   2  'Align Bottom
  145.       BackColor       =   &H00C0C0C0&
  146.       BorderStyle     =   0  'None
  147.       Height          =   281
  148.       Left            =   0
  149.       ScaleHeight     =   298.153
  150.       ScaleMode       =   0  'User
  151.       ScaleWidth      =   5665.189
  152.       TabIndex        =   13
  153.       Top             =   3465
  154.       Width           =   5655
  155.       Begin CommandButton NextButton 
  156.          Caption         =   ">"
  157.          FontBold        =   -1  'True
  158.          FontItalic      =   0   'False
  159.          FontName        =   "MS Sans Serif"
  160.          FontSize        =   12
  161.          FontStrikethru  =   0   'False
  162.          FontUnderline   =   0   'False
  163.          Height          =   287
  164.          Left            =   4200
  165.          TabIndex        =   21
  166.          Top             =   0
  167.          Width           =   375
  168.       End
  169.       Begin CommandButton LastButton 
  170.          Caption         =   ">|"
  171.          FontBold        =   -1  'True
  172.          FontItalic      =   0   'False
  173.          FontName        =   "MS Sans Serif"
  174.          FontSize        =   12
  175.          FontStrikethru  =   0   'False
  176.          FontUnderline   =   0   'False
  177.          Height          =   287
  178.          Left            =   4575
  179.          TabIndex        =   20
  180.          Top             =   0
  181.          Width           =   375
  182.       End
  183.       Begin CommandButton FirstButton 
  184.          Caption         =   "|<"
  185.          FontBold        =   -1  'True
  186.          FontItalic      =   0   'False
  187.          FontName        =   "MS Sans Serif"
  188.          FontSize        =   12
  189.          FontStrikethru  =   0   'False
  190.          FontUnderline   =   0   'False
  191.          Height          =   287
  192.          Left            =   0
  193.          TabIndex        =   19
  194.          Top             =   0
  195.          Width           =   375
  196.       End
  197.       Begin CommandButton PrevButton 
  198.          Caption         =   "<"
  199.          FontBold        =   -1  'True
  200.          FontItalic      =   0   'False
  201.          FontName        =   "MS Sans Serif"
  202.          FontSize        =   12
  203.          FontStrikethru  =   0   'False
  204.          FontUnderline   =   0   'False
  205.          Height          =   287
  206.          Left            =   375
  207.          TabIndex        =   18
  208.          Top             =   0
  209.          Width           =   375
  210.       End
  211.       Begin Label cStatusBar 
  212.          BackColor       =   &H00FFFFFF&
  213.          BorderStyle     =   1  'Fixed Single
  214.          Height          =   287
  215.          Left            =   749
  216.          TabIndex        =   14
  217.          Top             =   5
  218.          Width           =   3360
  219.       End
  220.    End
  221.    Begin VScrollBar cScrollBar 
  222.       Height          =   2616
  223.       LargeChange     =   3000
  224.       Left            =   5040
  225.       SmallChange     =   300
  226.       TabIndex        =   12
  227.       Top             =   720
  228.       Visible         =   0   'False
  229.       Width           =   252
  230.    End
  231.    Begin PictureBox cFields 
  232.       BackColor       =   &H00C0C0C0&
  233.       BorderStyle     =   0  'None
  234.       Height          =   375
  235.       Left            =   120
  236.       ScaleHeight     =   372
  237.       ScaleMode       =   0  'User
  238.       ScaleWidth      =   4812
  239.       TabIndex        =   9
  240.       Top             =   720
  241.       Width           =   4815
  242.       Begin TextBox cFieldData 
  243.          BackColor       =   &H00FFFFFF&
  244.          DataSource      =   "Data1"
  245.          ForeColor       =   &H00000000&
  246.          Height          =   288
  247.          Index           =   0
  248.          Left            =   1560
  249.          TabIndex        =   10
  250.          Top             =   0
  251.          Visible         =   0   'False
  252.          Width           =   3252
  253.       End
  254.       Begin Label cFieldName 
  255.          BackColor       =   &H00C0C0C0&
  256.          ForeColor       =   &H00000000&
  257.          Height          =   252
  258.          Index           =   0
  259.          Left            =   0
  260.          TabIndex        =   11
  261.          Top             =   60
  262.          Visible         =   0   'False
  263.          Width           =   1572
  264.       End
  265.    End
  266. End
  267. Option Explicit
  268.  
  269. 'form variables
  270. Dim FDS As dynaset            'current form's dynaset
  271. Dim FTblname As String        'form dynaset table name
  272. Dim FBM As String             'form bookmark
  273. Dim FNotFound As Integer      'used by find function
  274. Dim FAtTop As Integer         'top flag
  275. Dim FEditFlag As Integer      'edit mode
  276. Dim FAddNewFlag As Integer    'add mode
  277. Dim FFldDataChanged As Integer
  278. Dim FFindForm As New fFind    'find form instance
  279. Dim FCurrRec As Integer       'record counter
  280. Dim FNumbRows As Long         'total rows in dynaset
  281. Dim FDynaString As String     'dynaset open string
  282.  
  283. Sub AddButton_Click ()
  284.   On Error GoTo AddErr
  285.  
  286.   'set the mode
  287.   FDS.AddNew
  288.   cStatusBar = "Add record"
  289.   FAddNewFlag = True
  290.   If FDS.RecordCount > 0 Then
  291.     FBM = FDS.Bookmark
  292.   Else
  293.     FBM = ""
  294.   End If
  295.  
  296.   ChangeButtons.Visible = True
  297.   ViewButtons.Visible = False
  298.   NextButton.Enabled = False
  299.   FirstButton.Enabled = False
  300.   LastButton.Enabled = False
  301.   PrevButton.Enabled = False
  302.  
  303.   ClearDataFields
  304.   cFieldData(0).SetFocus
  305.   GoTo AddEnd
  306.  
  307. AddErr:
  308.   ShowError
  309.   Resume AddEnd
  310.  
  311. AddEnd:
  312.  
  313. End Sub
  314.  
  315. Sub CancelButton_Click ()
  316.    On Error Resume Next
  317.  
  318.    ChangeButtons.Visible = False
  319.    ViewButtons.Visible = True
  320.    NextButton.Enabled = True
  321.    FirstButton.Enabled = True
  322.    LastButton.Enabled = True
  323.    PrevButton.Enabled = True
  324.  
  325.    FEditFlag = False
  326.    FAddNewFlag = False
  327.    If FBM <> "" Then FDS.Bookmark = FBM
  328.    DisplayCurrentRecord
  329.  
  330. End Sub
  331.  
  332. Sub cFieldData_Change (Index As Integer)
  333.   'just set the flag if data is changed
  334.   'it gets reset to false when a new record is displayed
  335.   FFldDataChanged = True
  336. End Sub
  337.  
  338. Sub cFieldData_KeyDown (Index As Integer, KeyCode As Integer, Shift As Integer)
  339.   If KeyCode = &H73 Then   'F4
  340.     'cFieldName_DblClick Index
  341.  
  342.   ElseIf KeyCode = 34 And cScrollBar.Visible = True Then
  343.     'pagedown with > 10 fields
  344.     cScrollBar = cScrollBar - 3000
  345.  
  346.   ElseIf KeyCode = 33 And cScrollBar.Visible = True Then
  347.     'pageup with > 10 fields
  348.     cScrollBar = cScrollBar + 3000
  349.  
  350.   End If
  351. End Sub
  352.  
  353. Sub cFieldData_KeyPress (Index As Integer, KeyAscii As Integer)
  354.   'only allow return when in edit of add mode
  355.   If FEditFlag = True Or FAddNewFlag = True Then
  356.     If FDS(Index).Type = FT_STRING And Len(cFieldData(Index)) > FDS(Index).Size Then
  357.       Beep
  358.       MsgBox "Field Length Exceeded!", 48
  359.       KeyAscii = 0
  360.       Exit Sub
  361.     End If
  362.     If KeyAscii = 13 Then
  363.       KeyAscii = 0
  364.       SendKeys "{Tab}"
  365.     End If
  366.  
  367.   'throw away the keystrokes if not in add or edit mode
  368.   ElseIf FEditFlag = False And FAddNewFlag = False Then
  369.     KeyAscii = 0
  370.   End If
  371.  
  372. End Sub
  373.  
  374. Sub cFieldData_LostFocus (Index As Integer)
  375.   On Error GoTo FldDataErr
  376.  
  377.   If FFldDataChanged = True Then
  378.     'store the data in the field
  379.     FDS(Index) = cFieldData(Index)
  380.   End If
  381.  
  382.   GoTo FldDataEnd
  383.  
  384. FldDataErr:
  385.   ShowError
  386.   Resume FldDataEnd
  387.  
  388. FldDataEnd:
  389.   'reset for valid or error condition
  390.   FFldDataChanged = False
  391.  
  392. End Sub
  393.  
  394. Sub ClearDataFields ()
  395.   Dim i As Integer
  396.  
  397.   'clear out the fields on the main form
  398.   For i = 0 To FDS.Fields.Count - 1
  399.     cFieldData(i) = ""
  400.   Next
  401. End Sub
  402.  
  403. Sub CloseButton_Click ()
  404.   If Not gStoredFlag Then ' this query did not come from storage
  405.     fQuery.RunSaveQryButton.Caption = "&Store Query "
  406.     fQuery.RunSaveQryButton.Enabled = True
  407.     fQuery.RunQueryButton.Enabled = False
  408.     Else
  409.     fQuery.RunSaveQryButton.Caption = "&Load Query"
  410.     fQuery.RunSaveQryButton.Enabled = False
  411.     fQuery.RunQueryButton.Enabled = False
  412.     'gStoredFlag = False
  413.   End If
  414.  
  415.   fQuery.Show
  416.   Unload Me
  417. End Sub
  418.  
  419. Sub cScrollBar_Change ()
  420.   Dim t As Integer
  421.  
  422.   t = cScrollBar
  423.   If (t - 720) Mod 300 = 0 Then
  424.     cFields.Top = t
  425.   Else
  426.     cFields.Top = ((t - 720) \ 300) * 300 + 720
  427.   End If
  428.  
  429. End Sub
  430.  
  431. Sub DelButton_Click ()
  432.   On Error GoTo DelRecErr
  433.  
  434.   If MsgBox("Delete Current Record?", MSGBOX_TYPE) = YES Then
  435.     FDS.Delete
  436.     If gfTransPending Then gfDBChanged = True
  437.     If FDS.EOF = False Then
  438.       FDS.MoveNext
  439.     End If
  440.     FNumbRows = FNumbRows - 1
  441.     DisplayCurrentRecord
  442.   End If
  443.  
  444.   GoTo DelRecEnd
  445.  
  446. DelRecErr:
  447.   ShowError
  448.   gstDynaString = ""
  449.   Resume DelRecEnd
  450.  
  451. DelRecEnd:
  452.  
  453. End Sub
  454.  
  455. Sub DisplayCurrentRecord ()
  456.    Dim i As Integer
  457.    Dim cst As String    'current status bar
  458.  
  459.    On Error GoTo DCRErr
  460.  
  461.    SetHourGlass Me
  462.  
  463.    cst = "Record "
  464.    'check BOF/EOF flag so we know if we
  465.    'are sitting on a valid record
  466.    If FAddNewFlag = True Then
  467.      cst = cst + CStr(FCurrRec) + " of " + CStr(FNumbRows)
  468.    Else
  469.      If FDS.BOF = True Then
  470.        cst = cst + "(BOF) of " + CStr(FNumbRows)
  471.        ClearDataFields
  472.      ElseIf FDS.EOF = True Then
  473.        cst = cst + "(EOF) of " + CStr(FNumbRows)
  474.        ClearDataFields
  475.      Else
  476.        cst = cst + CStr(FCurrRec) + " of " + CStr(FNumbRows)
  477.        'place the data in the form fields
  478.        For i = 0 To FDS.Fields.Count - 1
  479.          If FDS(i).Type = FT_MEMO Then
  480.            If FDS(i).FieldSize() < GETCHUNK_CUTOFF Then
  481.              cFieldData(i) = StripNonAscii(vFieldVal(FDS(i)))
  482.            Else
  483.              cFieldData(i) = StripNonAscii(vFieldVal(FDS(i).GetChunk(0, GETCHUNK_CUTOFF)))
  484.            End If
  485.          ElseIf FDS(i).Type = FT_STRING Then
  486.            cFieldData(i) = StripNonAscii(vFieldVal(FDS(i)))
  487.          Else
  488.            cFieldData(i) = vFieldVal(FDS(i))
  489.          End If
  490.        Next
  491.      End If
  492.    End If
  493.    If gfUpdatable = False Then cst = cst + "  [Not Updatable]"
  494.    cStatusBar = cst
  495.    'set the flag
  496.    FFldDataChanged = False
  497.  
  498.    GoTo DCREnd
  499.  
  500. DCRErr:
  501.   ShowError
  502.   gstDynaString = ""
  503.   Resume DCREnd
  504.  
  505. DCREnd:
  506.    ResetMouse Me
  507.  
  508. End Sub
  509.  
  510. Sub EditButton_Click ()
  511.    On Error GoTo EditErr
  512.  
  513.    FDS.Edit
  514.    cStatusBar = "Edit record"
  515.    FEditFlag = True
  516.    cFieldData(0).SetFocus
  517.    FBM = FDS.Bookmark
  518.  
  519.    ChangeButtons.Visible = True
  520.    ViewButtons.Visible = False
  521.    NextButton.Enabled = False
  522.    FirstButton.Enabled = False
  523.    LastButton.Enabled = False
  524.    PrevButton.Enabled = False
  525.  
  526.    GoTo EditEnd
  527.  
  528. EditErr:
  529.   ShowError
  530.   Resume EditEnd
  531.  
  532. EditEnd:
  533.  
  534. End Sub
  535.  
  536. Sub FilterButton_Click ()
  537.   On Error GoTo FilterErr
  538.  
  539.   Dim bm As String
  540.   Dim ds1 As dynaset, ds2 As dynaset
  541.   
  542.   Dim i As Integer
  543.   bm = FDS.Bookmark        'save the bookmark
  544.   Set ds1 = FDS            'save the dynaset
  545.  
  546.     fFIlter.cExpr.Text = ""
  547.     fFIlter.cFieldList.Clear
  548.     For i = 0 To FDS.Fields.Count - 1
  549.       fFIlter.cFieldList.AddItem Mid(cFieldName(i), 1, Len(cFieldName(i)) - 1)
  550.     Next
  551.   
  552.  
  553.    MsgBar "Enter Search Parameters", False
  554.  
  555.   fFIlter.Show MODAL
  556.  
  557.   
  558.   'gFilterStr = InputBox("Enter Filter Expression:")
  559.   If gFilterStr = "" Then Exit Sub
  560.  
  561.   SetHourGlass Me
  562.   MsgBar "Setting New Filter", True
  563.   FDS.Filter = gFilterStr
  564.   Set ds2 = FDS.CreateDynaset()            'establish the filter
  565.   Set FDS = ds2            'assign back to original dynaset object
  566.  
  567.   'everything must be okay so redisplay form on 1st record
  568.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  569.   FCurrRec = 1
  570.   DisplayCurrentRecord     'display field values
  571.   FAtTop = True
  572.   ResetMouse Me
  573.   MsgBar "", False
  574.   GoTo FilterEnd
  575.  
  576. FilterErr:
  577.   ResetMouse Me
  578.   MsgBar "", False
  579.   ShowError
  580.   Set FDS = ds1            're-assign back to original
  581.   FDS.Bookmark = bm        'go back to original record
  582.   Resume FilterEnd
  583.  
  584. FilterEnd:
  585.  
  586. End Sub
  587.  
  588. Sub FindButton_Click ()
  589.   Dim i As Integer
  590.   Dim bm As String
  591.  
  592.   On Error GoTo FindErr
  593.  
  594.   'load the column names into the find form
  595.   If FFindForm.cFieldList.ListCount = 0 Then
  596.     For i = 0 To FDS.Fields.Count - 1
  597.       FFindForm.cFieldList.AddItem Mid(cFieldName(i), 1, Len(cFieldName(i)) - 1)
  598.     Next
  599.   End If
  600.  
  601. FindStart:
  602.  
  603.   'reset the flags
  604.   gfFindFailed = False
  605.   gfFromTableView = False
  606.   FNotFound = False
  607.  
  608.   MsgBar "Enter Search Parameters", False
  609.   FFindForm.Show MODAL
  610.   MsgBar "Searching for New Record", True
  611.   If gfFindFailed = True Then   'find cancelled
  612.     GoTo AfterWhile
  613.   End If
  614.  
  615.   SetHourGlass Me
  616.  
  617.    i = FFindForm.cFieldList.ListIndex
  618.    'search for the record
  619.    bm = FDS.Bookmark
  620.    If FDS(i).Type = FT_STRING Or FDS(i).Type = FT_MEMO Then
  621.      FDS.FindFirst FDS(i).Name + " " + gstFindOp + " '" + gstFindExpr + "'"
  622.    Else
  623.      FDS.FindFirst FDS(i).Name + gstFindOp + gstFindExpr
  624.    End If
  625.    FNotFound = FDS.NoMatch
  626.  
  627. AfterWhile:
  628.  
  629.    ResetMouse Me
  630.  
  631.    If gfFindFailed = True Then   'go back to top
  632.      FDS.Bookmark = bm
  633.    ElseIf FNotFound Then
  634.      Beep
  635.      MsgBox "Record Not Found", 48
  636.      FDS.Bookmark = bm
  637.      GoTo FindStart
  638.    Else
  639.      bm = FDS.Bookmark
  640.      FDS.MoveFirst
  641.      FCurrRec = 1
  642.      While FDS.Bookmark <> bm
  643.        FCurrRec = FCurrRec + 1
  644.        FDS.MoveNext
  645.      Wend
  646.    End If
  647.  
  648.    DisplayCurrentRecord
  649.  
  650.    GoTo FindEnd
  651.  
  652. FindErr:
  653.    ResetMouse Me
  654.    If Err <> EOF_ERR Then
  655.      ShowError
  656.      gstDynaString = ""
  657.      Resume FindEnd
  658.    Else
  659.      FNotFound = True
  660.      Resume Next
  661.    End If
  662.  
  663. FindEnd:
  664.    MsgBar "", False
  665.  
  666. End Sub
  667.  
  668. Sub FirstButton_Click ()
  669.    Dim ds As String
  670.    On Error GoTo GoFirstError
  671.  
  672.    FDS.MoveFirst
  673.    FCurrRec = 1
  674.    DisplayCurrentRecord
  675.    FAtTop = True
  676.  
  677.    GoTo GoFirstEnd
  678.  
  679. GoFirstError:
  680.    ShowError
  681.    Resume GoFirstEnd
  682.  
  683. GoFirstEnd:
  684.    ResetMouse Me
  685.    MsgBar "", False
  686.  
  687. End Sub
  688.  
  689. Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
  690.   If FEditFlag = True Or FAddNewFlag = True Then Exit Sub
  691.   
  692.   Select Case KeyCode
  693.     Case 35                'end
  694.       Call LastButton_Click
  695.     Case 36                'home
  696.       Call FirstButton_Click
  697.     Case 38                'up arrow
  698.       If Shift = 2 Then
  699.         Call FirstButton_Click
  700.       Else
  701.         Call PrevButton_Click
  702.       End If
  703.     Case 40                'down arrow
  704.       If Shift = 2 Then
  705.         Call LastButton_Click
  706.       Else
  707.         Call NextButton_Click
  708.       End If
  709.     Case 114                'F3
  710.       Call FindButton_Click
  711.  
  712.   End Select
  713.  
  714. End Sub
  715.  
  716. Sub Form_Load ()
  717.  
  718.    Dim t As TableDef       'local table structure
  719.    Dim sp As Integer       'starting point of table name
  720.    Dim ep As Integer       'ending point of table name
  721.    Dim ds As String        'temp dynaset name string
  722.    Dim wh As String        'where clause
  723.  
  724.    Dim ft As Integer
  725.    Dim i As Integer, j As Integer
  726.    Dim fn As String        'field name
  727.    Dim l As Long
  728.  
  729.    
  730.    On Error GoTo DynasetErr
  731.  
  732.    SetHourGlass Me
  733.    MsgBar "Opening Dynaset", True
  734.  
  735.    If gfFromSQL = True Then
  736.      ds = fQuery!cCriteria
  737.         If gfFromSQL Then  ' from SQL Statement
  738.             gstDynaString = fQuery!cCriteria ' so we can store
  739.         End If
  740.    Else
  741.        ds = gstDynaString
  742.    End If
  743.    
  744.    'attemp to open the dynaset
  745.      Set FDS = gCurrentDB.CreateDynaset(ds)
  746.    'parse off table name to store in global gstTblName
  747.    wh = ""
  748.    sp = InStr(1, UCase(ds), "FROM")
  749.    If sp > 0 Then
  750.      'must be a "select from" statement
  751.      sp = sp + 5
  752.      For ep = sp To Len(ds)
  753.        'search for a space or the end of ds
  754.        If Mid$(ds, ep, 1) = " " Then
  755.          'get where clause if there is one
  756.          wh = Mid$(ds, sp, Len(ds) - sp + 1)
  757.          Exit For
  758.        End If
  759.      Next
  760.      FTblname = UCase(Mid$(ds, sp, ep - sp))
  761.      gTblname = FTblname  ' global for filter and sort
  762.  
  763.      If wh = "" Then wh = FTblname
  764.    Else
  765.      'must be a table name only
  766.      FTblname = UCase(ds)
  767.      wh = FTblname
  768.    End If
  769.  
  770.    FDynaString = wh
  771.  
  772.    'show the first record
  773.    FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  774.  
  775.    'load the controls on the dynaset form
  776.    cFieldName(0).Visible = True
  777.    cFieldData(0).Visible = True
  778.    ft = FDS(0).Type
  779.    cFieldData(0).Width = GetFieldWidth(ft)
  780.    cFieldData(0).TabIndex = 0
  781.    For i = 1 To FDS.Fields.Count - 1
  782.      cFields.Height = cFields.Height + 300
  783.      Load cFieldName(i)
  784.      cFieldName(i).Top = cFieldName(i - 1).Top + 300
  785.      cFieldName(i).Visible = True
  786.      Load cFieldData(i)
  787.      cFieldData(i).Top = cFieldData(i - 1).Top + 300
  788.      cFieldData(i).Visible = True
  789.      ft = FDS.Fields(i).Type
  790.      cFieldData(i).Width = GetFieldWidth(ft)
  791.      cFieldData(i).TabIndex = i
  792.    Next
  793.  
  794.    'resize main window
  795.    If i <= 10 Then
  796.      Height = ((i + 1) * 300) + 1400
  797.    Else
  798.      Height = 4368
  799.      Width = Width + 260
  800.      cScrollBar.Visible = True
  801.      cScrollBar.Min = 720
  802.      cScrollBar.Max = 720 - (i * 300) + 3000
  803.    End If
  804.  
  805.    'display the field names
  806.    For i = 0 To FDS.Fields.Count - 1
  807.      cFieldName(i) = UCase(FDS(i).Name) + ":"
  808.    Next
  809.  
  810.    FCurrRec = 1
  811.    DisplayCurrentRecord      'display field values
  812.    FAtTop = True
  813.      '
  814.      Caption = "Dynaset: " + FTblname
  815.  
  816.    Me.Left = (screen.Width - Me.Width) / 2
  817.    Me.Top = (screen.Height - Me.Height) / 2
  818.    
  819.    'Width = 5805
  820.    'Left = 1000
  821.    'Top = 1000
  822.      Me.Show
  823.      fQuery.Hide
  824.  
  825.    GoTo OkayEnd
  826.  
  827. DynasetErr:
  828.    ShowError
  829.    ResetMouse Me
  830.    gstDynaString = ""
  831.    Unload Me
  832.    fQuery.Show
  833.    MsgBar "", False
  834.    Exit Sub
  835.    Resume OkayEnd
  836.  
  837. OkayEnd:
  838.    ResetMouse Me
  839.    MsgBar "", False
  840.  
  841. End Sub
  842.  
  843. Sub Form_Paint ()
  844.  
  845.   Outlines Me
  846. End Sub
  847.  
  848. Sub Form_Resize ()
  849.   On Error Resume Next
  850.  
  851.   Dim h As Integer, i As Integer
  852.   Dim totw As Integer
  853.  
  854.   If WindowState <> 1 Then   'not minimized
  855.     MsgBar "Resizing Form", True
  856.     'make sure the form is lined up on a field
  857.     h = Height
  858.     If (h - 1420) Mod 300 <> 0 Then
  859.       Height = ((h - 1420) \ 300) * 300 + 1420
  860.     End If
  861.     'resize the status bar
  862.     StatBox.Top = Height - 650
  863.     'resize the scrollbar
  864.     cScrollBar.Height = StatBox.Top - (ViewButtons.Top - FieldHeader.Height) - 960
  865.     cScrollBar.Left = Width - 360
  866.     If FDS.Fields.Count > 10 Then
  867.       cFields.Width = Width - 260
  868.       totw = cScrollBar.Left - 20
  869.     Else
  870.       cFields.Width = Width - 20
  871.       totw = Width - 50
  872.     End If
  873.     FieldHeader.Width = Width - 20
  874.     'widen the fields if possible
  875.     For i = 0 To FDS.Fields.Count - 1
  876.       cFieldName(i).Width = .3 * totw
  877.       cFieldData(i).Left = cFieldName(i).Width + 20
  878.       If FDS(i).Type = FT_STRING Or FDS(i).Type = FT_MEMO Then
  879.         cFieldData(i).Width = .7 * totw - 250
  880.       End If
  881.     Next
  882.     'FieldValueLabel.Left = cFieldData(0).Left
  883.     cStatusBar.Width = Width - 1600
  884.     NextButton.Left = cStatusBar.Width + 745
  885.     LastButton.Left = NextButton.Left + 370
  886.   End If
  887.   MsgBar "", False
  888. End Sub
  889.  
  890. Sub Form_Unload (Cancel As Integer)
  891.   On Error Resume Next
  892.   'gstDynaString = ""
  893.   Unload FFindForm
  894.   'get rid of attached find form
  895.   FDS.Close          'close the form dynaset
  896.   MsgBar "", False
  897. End Sub
  898.  
  899. Sub LastButton_Click ()
  900.    On Error GoTo GoLastError
  901.  
  902.    FDS.MoveLast
  903.    'show the current record
  904.    FCurrRec = FNumbRows
  905.    DisplayCurrentRecord
  906.  
  907.    GoTo GoLastEnd
  908.  
  909. GoLastError:
  910.    ShowError
  911.    Resume GoLastEnd
  912.  
  913. GoLastEnd:
  914.  
  915. End Sub
  916.  
  917. Sub NextButton_Click ()
  918.    On Error GoTo GoNextError
  919.  
  920.    FDS.MoveNext
  921.    'show the current record
  922.    FCurrRec = FCurrRec + 1   'bump the record counter
  923.    DisplayCurrentRecord
  924.    FAtTop = False
  925.  
  926.    GoTo GoNextEnd
  927.  
  928. GoNextError:
  929.    ShowError
  930.    Resume GoNextEnd
  931.  
  932. GoNextEnd:
  933.  
  934. End Sub
  935.  
  936. Sub PrevButton_Click ()
  937.    On Error GoTo GoPrevError
  938.  
  939.    FDS.MovePrevious
  940.    'show the current record
  941.    FCurrRec = FCurrRec - 1   'bump the record counter back
  942.    DisplayCurrentRecord
  943.    FAtTop = False
  944.  
  945.    GoTo GoPrevEnd
  946.  
  947. GoPrevError:
  948.    ShowError
  949.    Resume GoPrevEnd
  950.  
  951. GoPrevEnd:
  952.  
  953. End Sub
  954.  
  955. Sub SortButton_Click ()
  956.   On Error GoTo SortErr
  957.  
  958.   Dim bm As String
  959.   Dim ds1 As dynaset, ds2 As dynaset
  960.   
  961.   Dim i As Integer
  962.   gSortStr = ""
  963.  
  964.   bm = FDS.Bookmark        'save the bookmark
  965.   Set ds1 = FDS            'save the dynaset
  966.   
  967.   
  968.     fSort.cFieldList.Clear
  969.     For i = 0 To FDS.Fields.Count - 1
  970.       fSort.cFieldList.AddItem Mid(cFieldName(i), 1, Len(cFieldName(i)) - 1)
  971.     Next
  972.  
  973.  
  974.   fSort.Show MODAL
  975.   'gSortStr = InputBox("Enter Sort Column:")
  976.   If gSortStr = "" Then Exit Sub
  977.  
  978.   SetHourGlass Me
  979.   MsgBar "Setting New Sort Order", True
  980.   FDS.Sort = gSortStr
  981.   Set ds2 = FDS.CreateDynaset()            'establish the Sort
  982.   Set FDS = ds2            'assign back to original dynaset object
  983.  
  984.   'everything must be okay so redisplay form on 1st record
  985.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  986.   FCurrRec = 1
  987.   DisplayCurrentRecord     'display field values
  988.   FAtTop = True
  989.   ResetMouse Me
  990.   MsgBar "", False
  991.   GoTo SortEnd
  992.  
  993. SortErr:
  994.   ResetMouse Me
  995.   MsgBar "", False
  996.   ShowError
  997.   Set FDS = ds1            're-assign back to original
  998.   FDS.Bookmark = bm        'go back to original record
  999.   Resume SortEnd
  1000.  
  1001. SortEnd:
  1002.  
  1003. End Sub
  1004.  
  1005. Sub UpdateButton_Click ()
  1006.   On Error GoTo UpdateErr
  1007.  
  1008.   FDS.Update
  1009.   If gfTransPending Then gfDBChanged = True
  1010.  
  1011.   If FAddNewFlag = True Then
  1012.     FNumbRows = FNumbRows + 1
  1013.     FCurrRec = FNumbRows
  1014.     FDS.MoveLast             'move to the new record
  1015.   End If
  1016.  
  1017.   ChangeButtons.Visible = False
  1018.   ViewButtons.Visible = True
  1019.   NextButton.Enabled = True
  1020.   FirstButton.Enabled = True
  1021.   LastButton.Enabled = True
  1022.   PrevButton.Enabled = True
  1023.   FEditFlag = False
  1024.   FAddNewFlag = False
  1025.   DisplayCurrentRecord
  1026.  
  1027.   GoTo UpdateEnd
  1028.  
  1029. UpdateErr:
  1030.   ShowError
  1031.   Resume UpdateEnd
  1032.  
  1033. UpdateEnd:
  1034.  
  1035. End Sub
  1036.  
  1037.